# 由STM32确定整个通信速度，raspi接收一个包,返回一个包
import SerialProtocol as myserial
import time
import struct
import random

center_x = 1.0
center_y = 2.0
center_angle = 3.0
door_status = 1
    
receive_data = myserial.Receive_Data_C()

def example_callback(data):
    print(f"Received: {data.decode()}")
    return b"ACK"


def user_callback(data):
    # 返回接收数据
    global receive_data
    receive_data.data_arrange(data)
    receive_data.my_print()
    global center_x,center_y,center_angle
    temp_data = bytearray()
    temp_data += struct.pack('fffI', center_x, center_y, center_angle,door_status)
    # temp_data.append()
    return temp_data


try:
    handler = myserial.SerialProtocolHandler(port='/dev/serial0', callback=user_callback)
    handler.start_quene()
    while True:
        rand = random.uniform(-0.5, 0.5)
        center_x = 1.0 + rand
        center_y = 2.0 + rand
        center_angle = 3.0 + rand
        time.sleep(1)
except KeyboardInterrupt:
    handler.stop()
